<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
use Hyperf\Server\Event;
use Hyperf\Server\Server;
use Swoole\Constant;

return [
    'mode' => SWOOLE_PROCESS,
    'servers' => [
        [
            'name' => 'http',
            'type' => Server::SERVER_HTTP,
            'host' => '0.0.0.0',
            'port' => (int) env('HTTP_SERVER', 19501),
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
            ],
        ],
        [
            'name' => 'tcp',
            'type' => Server::SERVER_BASE,
            'host' => '0.0.0.0',
            'port' => (int) env('TCP_SERVER', 19502),
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                Event::ON_RECEIVE => [App\Controller\Server\TcpServerController::class, 'onReceive'],
            ],
            'settings' => [
                // 按需配置
            ],
        ],
        // [
        //     'name' => 'socket-io',
        //     'type' => Server::SERVER_WEBSOCKET,
        //     'host' => '0.0.0.0',
        //     'port' => 39503,
        //     'sock_type' => SWOOLE_SOCK_TCP,
        //     'callbacks' => [
        //         Event::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],
        //         Event::ON_MESSAGE => [Hyperf\WebSocketServer\Server::class, 'onMessage'],
        //         Event::ON_CLOSE => [Hyperf\WebSocketServer\Server::class, 'onClose'],
        //     ],
        // ],
        // [
        //     'name' => 'ws',
        //     'type' => Server::SERVER_WEBSOCKET,
        //     'host' => '0.0.0.0',
        //     'port' => (int) env('WEBSOCKET_SERVER', 19503),
        //     'sock_type' => SWOOLE_SOCK_TCP,
        //     'callbacks' => [
        //         Event::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],
        //         Event::ON_MESSAGE => [Hyperf\WebSocketServer\Server::class, 'onMessage'],
        //         Event::ON_CLOSE => [Hyperf\WebSocketServer\Server::class, 'onClose'],
        //     ],
        //     'settings'  => [
        //         // 设置心跳检测
        //         // 'heartbeat_idle_time'      => 60, // 表示一个连接如果600秒内未向服务器发送任何数据，此连接将被强制关闭heartbeat_idle_time 未设置时默认为 interval 的两倍
        //         'heartbeat_check_interval' => 30,  // 表示每30秒遍历一次
        //     ]
        // ],
        // [
        //     'name' => 'mqtt',
        //     'type' => Server::SERVER_BASE,
        //     'host' => '0.0.0.0',
        //     'port' => env('MQTT_SERVER', 19504),
        //     'sock_type' => SWOOLE_SOCK_TCP,
        //     'callbacks' => [
        //         Event::ON_RECEIVE => [Hyperf\MqttServer\MQTTServer::class, 'onReceive'],
        //     ],
        // ],
    ],
    'settings' => [
        // Task Worker 数量，根据您的服务器配置而配置适当的数量
        'task_worker_num' => 4,
        // 因为 `Task` 主要处理无法协程化的方法，所以这里推荐设为 `false`，避免协程下出现数据混淆的情况
        'task_enable_coroutine' => false,
        // 静态资源
        'document_root' => 'public',
        'enable_static_handler' => true,

        Constant::OPTION_ENABLE_COROUTINE => true,
        Constant::OPTION_WORKER_NUM => 8,
        Constant::OPTION_PID_FILE => 'runtime/hyperf.pid',
        Constant::OPTION_OPEN_TCP_NODELAY => true,
        Constant::OPTION_MAX_COROUTINE => 100000,
        Constant::OPTION_OPEN_HTTP2_PROTOCOL => true,
        Constant::OPTION_MAX_REQUEST => 100000,
        Constant::OPTION_SOCKET_BUFFER_SIZE => 2 * 1024 * 1024,
        Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024,
        Constant::OPTION_PACKAGE_MAX_LENGTH => 10 * 1024 * 1024,
    ],
    'callbacks' => [
        Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
        Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
        Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
        // Task callbacks
        Event::ON_TASK => [Hyperf\Framework\Bootstrap\TaskCallback::class, 'onTask'],
        Event::ON_FINISH => [Hyperf\Framework\Bootstrap\FinishCallback::class, 'onFinish'],
    ],
];
